package com.sizu.web;


import com.sizu.common.dto.ParaDto;
import com.sizu.common.vo.ResultEntity;
import com.sizu.entity.CgPara;
import com.sizu.service.ICgParaService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 高旌洋
 * @since 2020-03-25
 */
@RestController
@RequestMapping("para/cgPara")
public class CgParaController {

    @Autowired
    private ICgParaService paraService;

    /**
     * 查询 cg_para表数据
     * @return
     */
    @GetMapping
    public ResultEntity findAll(){
        List<CgPara> paraList = paraService.selectList(null);
        return ResultEntity.ok(paraList);
    }

    /**
     * 根据ID查询cg_para表数据
     * @param id
     * @return
     */
    @GetMapping("/findById")
    public ResultEntity findById(Integer id){
        CgPara para = paraService.selectById(id);
        return ResultEntity.ok(para);
    }

    /**
     * 添加cg_para表数据
     * @param paraDto
     * @return
     */
    @PostMapping("/save")
    public ResultEntity save(@RequestBody ParaDto paraDto){
        CgPara cgPara = new CgPara();
        BeanUtils.copyProperties(paraDto,cgPara);
        paraService.insert(cgPara);
        return ResultEntity.ok("200","添加成功",null);
    }

    /**
     * 根据ID删除cg_para表数据
     * @param id
     * @return
     */
    @GetMapping("/deleteById")
    public ResultEntity delById(Integer id){
        paraService.deleteById(id);
        return ResultEntity.ok("200","删除成功",null);
    }
}
